
import java.util.StringTokenizer;

/**
 *
 * @author Mario
 */
public class validarDireccionIp {

    public static boolean validar( String dir ) {        
        StringTokenizer st = new StringTokenizer( dir, "." );
        if ( st.countTokens() != 4 ) {
            return false;
        }

        char ch = dir.charAt(dir.length()-1);
        if(ch == '.') return false;

        while ( st.hasMoreTokens() ) {
            String nro = st.nextToken();
            if ( ( nro.length() > 3 ) || ( nro.length() < 1 ) ) {
                return false;
            }
            int nroInt = 0;
            try {
                nroInt = Integer.parseInt( nro );
            }
            catch ( NumberFormatException s ) {
                return false;
            }
            if ( ( nroInt < 0 ) || ( nroInt > 255 ) ) {
                return false;
            }
        }
        return true;
    }
}
